<template>
  <div style="width:100px;height:200px;">
    <div id="objectdiv" style="width:100%;height:100%"></div>
  </div>
</template>

<script>
import OFD  from '@/utils/fuxinOfd/foxit.ofd.ocx.new.js'
import { vue } from '@/utils/fuxinOfd/vue.min.js'
import {sydm} from "@/api/archive/fileCollection/offlinReception";
export default {
  name: "index",
  props: ["ofdUrl"],
  data() {
    return {
      isLoaded: true,
      viewValue: "",
      xmlparam: "",
      file: [],
      obj: "",
      FileArr: [],
    }
  },
  computed: {

  },
  created(){
    var that = this
  },
  mounted () {
    //初始化插件
    // var width = document.documentElement.clientWidth
    // var height = document.documentElement.clientHeight
    const objectDiv = document.querySelector('#objectdiv');
    const width = objectDiv.clientWidth;
    const height = objectDiv.clientHeight;
    console.log(width, height)
    this.obj = OFD.OCX.init("objectdiv", width, height);
    this.obj.ready(this.obj._id);
    if (!("ActiveXObject" in window)) {
      this.obj.jsCallbackFun_InitSetting(this);
      this.obj.jsCallbackFun_UpdateInfo(this);
    }
  },
  watch: {
    ofdUrl: {
      handler(valNew, valOld) {
        this.$modal.loading("正在预览文件，请稍候...")
        setTimeout(res => {
          const url = window.location.protocol + '//' + window.location.host + process.env.VUE_APP_BASE_API + `/archive/detail/viewOfd?token=` + valNew
          console.log(url)
          this.$modal.closeLoading()
          this.obj.openFile(url, false)
        })
      },
      immediate: true,
    }
  },
  methods: {
    //插件调用方法
    initSetting() {
      //obj.setZoomMode('2');
      sydm({
        sydm: "yulan"
      }).then(res => {
        console.log(res.data.synr, "水印")
        this.synr = res.data.synr;
        // let waterMarkInfo = "单位名称" + '\n' + new Date().toLocaleString('zh', {hour12: false}) + ' \n' + 'ip地址'
        // console.log('waterMarkInfo'+waterMarkInfo)
        var xmlParam = "<setinfo type=\"barinfo\">" +
          "<barinfo1>" +
          "<parameter name=\"pages\" value=\"1-2000\"/>" +
          "<parameter name=\"rotate\" value=\"0\"/>" +
          "<parameter name=\"xpostype\" value =\"right\"/>" +
          "<parameter name=\"ypostype\" value=\"absolute\"/>" +
          "<parameter name=\"x\" value=\"0\"/>" +
          "<parameter name=\"y\" value=\"5\"/>" +
          "<parameter name=\"h\" value=\"500\"/>" +
          "<parameter name=\"w\" value=\"500\"/>" +
          "<parameter name=\"savewatermark\" value=\"0\"/>" +
          "<parameter name=\"istile\" value=\"1\"/>" +
          "<parameter name=\"show\" value=\"1\"/>" +
          "<parameter name=\"print\" value=\"1\"/>" +
          "<parameter name=\"strcont\" font=\"仿宋_GB2312\" size=\"18\"  color=\"DCDFE6\">" + res.data.synr + "</parameter>" +
          "</barinfo1>" +
          "</setinfo >";
        //obj.setCompositeVisible("sign", true);
        //window.open(base64File);
        this.obj.setMaxCopies(1);
        console.log(xmlParam);
        this.obj.addTrackInfo(xmlParam);
        // this.obj.printFile("2",1);
      })
    },

    // 打开文件
    // fx_openFile: function () {
    //   var res = obj.openFile("http://pmo.htfoxit.com:89/foxit-upload-ofd/download.do?fileid=323f23b857474fd39a9c678ce2f5e450&userid=78c8e9917bac40c6b2d83b8ad117ed9a&" + Math.random(), false);
    //   //var res = obj.openFile("D:/1.ofd");
    //   //  document.getElementById("btnprint").disabled = false;
    //   //  document.getElementById("btnset").disabled = false;
    //   //  document.getElementById("btngray").disabled = false;
    //   //  document.getElementById("btnopen").disabled = true;
    // },

    // 回调事件：包括翻页、打印、打印设置
    UpdateInfo(strkey, strValue) {
      console.log(strkey);
      if (strkey == "GetCurPageIndex") {
        var curPageIndex = this.obj.getCurPageIndex();
      } else if (strkey == "Print") {
        var log = this.obj.getLogFileContent();
      }
    },
  }
}
</script>

<style scoped>

</style>
